package com.umer.pinban.customer;

import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.common.bean.InfoResult;
import com.common.ui.barlibrary.ImmersionBar;
import com.common.utils.Constants;
import com.common.utils.GlideUtils;
import com.common.utils.GsonUtils;
import com.common.utils.SpUtil;
import com.umer.pinban.R;
import com.umer.pinban.adapter.customer.CustomerLookXiaoFeiRecordAdapter;
import com.umer.pinban.base.BasicActivity;
import com.umer.pinban.bean.customer.XiaoFeiRecordBean;
import com.umer.pinban.bean.customer.XiaoFeiRecordItemBean;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class LookXiaoFeiRecordActivity extends BasicActivity {

    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.image)
    ImageView image;
    private XiaoFeiRecordBean xiaoFeiRecord;
    private CustomerLookXiaoFeiRecordAdapter customerLookXiaoFeiRecordAdapter;

    @Override
    public boolean isImmersionBarEnabled() {
        return true;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                //是否可以修改导航栏颜色，默认为true
                .navigationBarEnable(true)
                //导航栏颜色，不写默认黑色
                .navigationBarColor(R.color.barcolor)
                .statusBarColor(R.color.colorPrimary)
                //解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                .fitsSystemWindows(true)
                .init();
    }

    @Override
    public View isSupportLoadSirEnabled() {
        return null;
    }

    @Override
    public boolean isSupportSwipeBackEnabled() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_look_xiaofei_record;
    }

    @Override
    public void init() {
        String xiaohaorecord = SpUtil.getString(this, Constants.xiaohaorecord);
        xiaoFeiRecord = GsonUtils.getInstance().jsonToClass(xiaohaorecord, XiaoFeiRecordBean.class);
        if (xiaoFeiRecord != null) {
            tv1.setText(xiaoFeiRecord.getExpenseDate());
            tv2.setText(xiaoFeiRecord.getShopName()+"("+xiaoFeiRecord.getShopAddress()+")");
            List<XiaoFeiRecordItemBean> infos = xiaoFeiRecord.getCommodityList();
            customerLookXiaoFeiRecordAdapter = new CustomerLookXiaoFeiRecordAdapter(this, infos,
                    R.layout.activity_look_xiaofei_record_item);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
            recycler.setLayoutManager(linearLayoutManager);
            recycler.setAdapter(customerLookXiaoFeiRecordAdapter);
            String path = xiaoFeiRecord.getVoucherPath();
            if(!TextUtils.isEmpty(path)){
                GlideUtils.getInstance().loadImageView(this,Constants.IP_PORT_DEFAULT_PICTURE+path,image);
            }
        }
    }

    @Override
    public void loadData() {

    }

    @OnClick({R.id.linear_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.linear_back:
                finish();
                break;
            default:break;
        }
    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }
}
